﻿using System.ComponentModel;
using Caliburn.PresentationFramework.ApplicationModel;
using Microsoft.Practices.ServiceLocation;

namespace CI.ViewModels
{
    public sealed class SheetsViewModel : MultiPresenterManager, ISheetsViewModel
    {
        public SheetsViewModel()
        {
            DisplayName = "Work Sheets";
            PropertyChanged += SheetsViewModel_PropertyChanged;
            Open(new WelcomeSheetViewModel(), Opened);
        }

        private void SheetsViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "CurrentPresenter") NotifyOfPropertyChange(() => CurrentSheet);
        }

        public ISheetViewModel AddSheet(string name)
        {
            var diagramSheetView = ServiceLocator.Current.GetInstance<ISheetViewModel>();

            Open(diagramSheetView, Opened);

            return diagramSheetView;
        }

        public ISheetViewModel AddSheet(ISheetViewModel viewModel)
        {
            Open(viewModel, Opened);
            return viewModel;
        }


        public void ShutdownPresenter(IPresenter presenter)
        {
            this.Shutdown(presenter);
        }

        private static void Opened(bool obj)
        {
            //            throw new NotImplementedException();
        }

        public ISheetViewModel CurrentSheet
        {
            get { return base.CurrentPresenter as ISheetViewModel; }
        }
    }
}